<div class="pageContent">
    <form method="post"
        action="${rc.getContextPath()}/manage/defectAttribute/saveDefectAttribute"
        class="pageForm required-validate"
        onsubmit="return checkFormInput(this);">
        <div class="pageFormContent"  >
          <div style="width:350px;float:left; ">
            <input type="hidden" name="navTabId" value="${navTabId!''}">
            <input type="hidden" name="id"
                value="<#if (defectAttribute.attributeText)??>${defectAttribute.attributeCode!''}</#if>">
            <fieldset>
                <dl class="nowrap ">
                    <dt><@label key="defectAttributeCode.C,colon">缺陷属性编号：</@label></dt>
                    <dd>
                        <input name="attributeCode" value="<#if (defectAttribute.attributeCode)??>${defectAttribute.attributeCode!''}</#if>" 
                              size="22" type="text" maxlength="20" class="required  alphanumeric toUp" warn="<@label key='attributeCode.C,alreadyExists'>缺陷属性编号已存在</@label>"
                              <#if pattern!="add">
                              readonly="readonly"
                              <#else>
                              remote="${rc.getContextPath()}/manage/defectAttribute/validateDefectAttributeCode"
                             </#if>
                        />
                    </dd>
                </dl>
                <dl class="nowrap">
                    <dt><@label key="defectAttributeText.C,colon">缺陷属性描述：</@label></dt>
                    <dd>
                        <input name="attributeText"
                            value="<#if (defectAttribute.attributeText)??>${defectAttribute.attributeText!''}</#if>"
                            size="22" type="text" maxlength="60" class="required" 
                            <#if "view"==pattern>
                              readonly="readonly"
                            </#if>
                          />
                    </dd>
                </dl>
                <dl class="nowrap">
                    <dt><@label key="type.C,colon">类型：</@label></dt>
                    <dd>
                        <#if  ECode??&&(ECode?size>0)>
                        <input type="hidden" name="valueTypeECode" value="${defectAttribute.valueTypeECode!''}" />
                        <select id="valueTypeECode" class="required" value="${defectAttribute.valueTypeECode!''}" 
                            <#if "add"!=pattern>
                              disabled="disabled"
                            </#if>>
                                <#list ECode as eCode>
                                        <option value="${eCode.eCode!''}" 
                                            <#if eCode.eCode==defectAttribute.valueTypeECode>
                                                selected="selected" 
                                            </#if>
                                            >
                                            ${eCode.eCodeText!''}
                                        </option>
                                </#list>
                        </select>
                        </#if>
                    </dd>
                </dl>
                <dl class="nowrap">
                    <dt>&nbsp;</dt>
                    <dd>
                        <label><input type="checkbox" name="requiredFlag" value="1"
                            <#if "view"==pattern>
                            disabled="disabled"
                            </#if>
                            <#if
                            (defectAttribute.requiredFlag)?? && (defectAttribute.requiredFlag == 1)>
                            checked="true"</#if>><@label key="required.C">必填</@label></label>
                    </dd>
                </dl>
                <dl class="nowrap">
                    <dt>&nbsp;</dt>
                    <dd>
                        <label><input type="checkbox" name="lockFlag" value="1"
                            <#if "view"==pattern>
                            disabled="disabled"
                            </#if>
                            <#if
                            (defectAttribute.lockFlag)?? && (defectAttribute.lockFlag == 1)>
                            checked="true"</#if>><@label key="lock.C">锁定</@label></label>
                    </dd>
                </dl>
                <dl style="width: 350px; height: 90px;">
                    <dt><@label key='memo.C,colon'>备注：</@label></dt>
                    <dd>
                        <textarea style="width: 135px;" name="memo" maxlength="200" value="${defectAttribute.memo!''}" rows="4"><#if (defectAttribute.memo)??>${defectAttribute.memo!''}</#if></textarea>
                    </dd>
                </dl></fieldset>
                
            </div>
        
            <div id="rightPanel" style="float:left;width:220px;
            <#if defectAttribute.valueTypeECode??&&(defectAttribute.valueTypeECode=='enum') >
            display:block;
            <#else>
            display:none;
            </#if>
            ">
                <div class="panelBar">
                    <ul class="toolBar" style="height:25px;">
                        <li style="width:200px;">
                            <a class="add"  href="javascript:void(0);" onclick="_addRow();"  >
                                <span><@label key="add.B">新增</@label></span>
                            </a>
                        </li>
                    </ul>
                </div>
                <table  id="enumTable" <#if "modify"==pattern>layoutH="210"<#else>layoutH="130"</#if> class="table canopration"    width="90%" >
                    <thead>
                        <tr>
                            <th style="width:140px;"><@label key="Enumeration.C">枚举值</@label></th>
                            <th style="width:40px;"><@label key="opera.C">操作</@label></th>
                        </tr>
                    </thead>
                
                    <tBody id="enumTbody">
                    <#if defectAttribute.attributeEnum??&&(defectAttribute.attributeEnum?size>0) >
                        <#list defectAttribute.attributeEnum as attributeEnum>
                            <tr>
                                <td style="padding-top:3px;">
                                    <input class="required" type='text' style='width:110px;height:19px;'name='attributeValue' value="${attributeEnum.attributeValue!''}" >
                                </td>
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" class='btnDel' href='javascript:void(0)' onclick='_deleteRow(this);'>
                                        <@label key='delete.B'>删除</@label>
                                    </a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                    </tBody>
                </table>
    
            </div>
        </div>    
        <#if defectAttribute??>
            <#assign createInfo=defectAttribute>
            <#include "/common/createInfo.html">
        </#if>
        <div class="formBar">
            <ul>
                <#if pattern!="view">
                    <li>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button type="submit"><@label key="save.B">保存</@label></button>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="buttonActiveGrey">
                            <div class="buttonContent">
                                    <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                            </div>
                        </div>
                    </li>
                <#else>
                    <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                                <button type="button" class="close"><@label key="close.B">关闭</@label></button>
                        </div>
                    </div>
                </li>
                </#if>
            </ul>
        </div>
    </form>

<script>
function _addRow(){
    var gridTheadTh = $("#enumTable",  $.pdialog.getCurrent()).find("table thead th");
    var row="<tr><td style='width:"+$(gridTheadTh[0]).width()+"px;padding-top:3px;'><input type='text' class='required textInput'  style='width:110px;height:19px;'name='attributeValue' ></td>"+
    "<td style='width:"+$(gridTheadTh[1]).width()+"px;'>"+
    "<a title='"+"<@label key='delete.B'>删除</@label>'"+" class='btnDel' href='javascript:void(0)' onclick='_deleteRow(this);'><@label key='delete.B'>删除</@label></a></td></tr>";
    var tobdy=$("#enumTbody",$.pdialog.getCurrent());
    tobdy.append(row);
}

function _deleteRow(a){
    $(a).parents("tr").remove();
}
$(function(){
	var $page = DWZ.context();
    var $select=$("#valueTypeECode", $page);
    var $rightPanel=$("#rightPanel", $page);
    if($select.value==="enum")
    {
        $rightPanel.css("display","block");
    }
    
    $select.change(function(){
 		$('[name=valueTypeECode]', $page).val(this.value);
         if(this.value==='enum')
         {
             $rightPanel.css("display","block");
         }
         else
         {
             $rightPanel.css("display","none");
         }
     }).change();
    
});
    
function checkFormInput(that)
{
    var formCompleted=true;
    var $rightPanel=$("#rightPanel",$.pdialog.getCurrent());
    //若是枚举类型,验证枚举值填写是否完整
    if($rightPanel.css("display")==="block")
    {
        $("#enumTable tr",$.pdialog.getCurrent()).find("input").each(function(i,e){
                 var str=e.value;
                if(str.replace(/\s/g, "").length ==0)
                {
                    formCompleted=false;
                    return false;
                }
        });
    }
    if(formCompleted)
    {
    	var map = {};
        var repeat=false;
    	$("#enumTable tbody tr td:nth-child(1) input").each(function(){
    		if( this.value in map){
    			 repeat=true;
    			 return;
    		}else{
    			map[this.value] = this.value; 	
    		}
    	});
    	if(repeat){
    		 alertMsg.error("<@label key='enumValueCanNotRepeat.C'>枚举值不能重复！</@label>");
    		 return false;
    	}else{
    		 return validateCallback(that, dialogAjaxDone);
    	}
    }
    else
    {
        alertMsg.error("<@label key='enumValueNotCompleted.C'>枚举值填写不完整</@label>");
        return false;
    }
    

}
</script>
